import { Service } from "~/core/service";
import { NetService } from "~/util/net.service";
import { Inject, Debounce } from "~/core/decorator";
import { serviceManage } from "~/config/server";

export class UserService extends Service {

  @Inject(NetService)
  private netService: NetService;

  /**
   * 新增用户
   */
  createUser(data) {
    return this.netService.send({
      server: serviceManage.userController.createUser,
      data: {
        userName: data.userName,
        realName: data.realName,
        tel: data.tel,
        deptId: data.deptId,
        remark: data.remark
      }
    })
  }

  /**
   * 修改用户
   */
  updateUser(data) {
    return this.netService.send({
      server: serviceManage.userController.updateUser,
      data: {
        id: data.id,
        realName: data.realName,
        tel: data.tel,
        remark: data.remark,
        status: data.status
      }
    })
  }

  /**
   * 分页查询用户
   */
  findUserListByPage(data, page) {
    return this.netService.send({
      server: serviceManage.userController.findUserListByPage,
      data: {
        deptCode: data.deptCode,
        userName: data.userName,
        realName: data.realName,
        tel: data.tel
      },
      page: page
    })
  }

  /**
   * 用户分配角色
   */
  assignRoleToUser(data) {
    return this.netService.send({
      server: serviceManage.userController.assignRoleToUser,
      data: {
        userId: data.userId,
        roleIds: data.roleIds
      }
    })
  }

  /**
   * 查询用户可分配的角色
   * @param userId 
   */
  findAssignRoleList(userId) {
    return this.netService.send({
      server: serviceManage.userController.findAssignRoleList,
      append: userId
    })
  }
}